package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotation.LagouAutowired;
import com.lagou.edu.mvcframework.annotation.LagouController;
import com.lagou.edu.mvcframework.annotation.LagouRequestMapping;
import com.lagou.edu.mvcframework.annotation.LagouSecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @LagouSecurity注解位于Class上的测试Demo
 */
@LagouController
@LagouSecurity(value = {"zhangsan"})
@LagouRequestMapping("/classdemo")
public class DemoClassController {
    @LagouAutowired
    private IDemoService demoService;

    /**
     * URL：http://localhost:8080/classdemo/query1?username=zhangsan 可以登陆
     *      http://localhost:8080/classdemo/query1?username=lisi     无法登陆
     */
    @LagouRequestMapping("/query1")
    public String query1(HttpServletRequest request, HttpServletResponse response, String username) {
        return demoService.get(username);
    }

    /**
     * URL：http://localhost:8080/classdemo/query2?username=zhangsan 可以登陆
     *      http://localhost:8080/classdemo/query2?username=lisi     可以登陆
     */
    @LagouSecurity(value = {"lisi"})
    @LagouRequestMapping("/query2")
    public String query2(HttpServletRequest request, HttpServletResponse response, String username) {
        return demoService.get(username);
    }
}
